<?php
/**
 * Created by PhpStorm.
 * User: 13790
 * Date: 2018/3/22
 * Time: 15:28
 */

namespace app\common\model;


use think\Model;

class Base extends Model
{
    /**
     * 权限筛选
     */
    public function getChilds($data){

        $arr = [];
        foreach($data as $k=>$v){
            if($v['level'] == 0){
                foreach($data as $k1=>$v1){
                    if($v1['pid'] == $v['id']){
                        foreach($data as $k2=>$v2){
                            if($v2['pid'] == $v1['id']){
                                $v1['child'][] = $v2;
                            }
                        }
                        $v['child'][] = $v1;
                    }
                }
                $arr[] = $v;
            }
        }
        return $arr;
    }

}